#ifndef SUBTITLEPARSER_H
#define SUBTITLEPARSER_H

#include <mlt++/Mlt.h>
#include <QThread>
#include <iostream>
#include <QString>
#include <QStringList>
#include <QList>
#include <QFile>
#include <QTextStream>
#include <QFont>
#include <QColor>
#include <QTime>
#include <QSvgGenerator>
#include <QPainter>
#include <QDir>


struct SubtitleInfo{
    int id;
    int firstFrame;
    int lastFrame;
    QStringList texts;
};

class SubtitleParser : public QThread{
    Q_OBJECT
public:
    explicit SubtitleParser(int idTrack = 0, QObject *parent = 0);
    ~SubtitleParser();
    void run();
    void addSubtitleInTractor(Mlt::Tractor *tractor, int nFrames, QString fileName, int idTrack, QSize videoSize, QFont font, QColor color, double yPerc, double fps);
    Mlt::Playlist *getSubtitlePlaylist();


signals:
    void subtitleGenerated();

public slots:

private:
    int idTrack;
    int nFrames;
    Mlt::Playlist *subtitlePlaylist;
    QString fileName;
    QSize videoSize;
    QFont font;
    QColor color;
    double fps;
    double yPerc;
    Mlt::Tractor *tractor;
    QTime nullTime;
    void _setFileName(QString fileName);
    void _setFont(QFont font);
    void _setColor(QColor color);
    void _setYPerc(int yPerc);
    void _setFps(double fps);
    void _setVideoSize(QSize videoSize);
    void _setIdTrack(int idTrack);
    void _setTractor(Mlt::Tractor *tractor);
    void _setNFrames(int nFrames);
    QList<SubtitleInfo> *_getAllSubtitleInfoAndCreateSvgFiles(QTextStream &textStream);
    SubtitleInfo _getNextSubtitleInfo(QTextStream &textStream);
    void _genereSvgFile(SubtitleInfo subtitleInfo);
    void _genereVoidSvg(QString svgFileName);
    QString _getSvgFileName(QString subtitleFileName, int id);
    Mlt::Playlist *_createPlaylist(QList<SubtitleInfo> subtitleInfos);
    void _addPlaylistInTractor(Mlt::Playlist *subtitleTrack, int idTrack);
};

#endif // SUBTITLEPARSER_H
